package com.hehe.httpurlconnectiontest2;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * Created by lenove on 2017/11/7.
 *  这个类将流转化为二进制数组，完成后关闭流
 */

public class StreamTool {

    //从流中读取数据
    public static byte[] read(InputStream inStream) throws Exception{
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();

        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = inStream.read(buffer))!=-1){
            //数据传进输出流
            outStream.write(buffer,0,len);
        }
        //关闭流
        inStream.close();
        //输出流输出为字节数组
        return outStream.toByteArray();
    }
}
